$(function () {
    $("#page").load("/back/page.html");
    findAll();
});

function findAll() {
    let data = {};
    data.companyName = $("#companyName").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    $.ajax({
        url: '/back/company/findAllCompanyContact',
        data: data,
        type: 'post',
        dataType: 'json',
        success: function (data) {
            showIContact(data.list);
            $("#pageCount").html(data.number);
        }
    })
}
function showIContact(data) {
    let html = "";//定一个一个空得html
    for (let i = 0; i < data.length; i++) {
        html += '  <tr>\n' +
            '        <td>' + data[i].id + '</td>\n' +
            '        <td>' + data[i].companyName + '</td>\n' +
            '        <td>' + data[i].adress + '</td>\n' +
            '        <td>' + data[i].phone + '</td>\n' +
            '        <td>' + data[i].email + '</td>\n' +
            '        <td>' + data[i].fax + '</td>\n' +
            '        <td><img src="' + data[i].qrCode + '"> </td>\n' +
            '   <td><a  href="javascript:edit( ' + data[i].id + ')">编辑</a> <a  href="javascript:del( ' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#contactFindAll").html(html);//赋值
}
function edit(id) {
    localStorage.setItem("contactId", id);
    //sessionStorage.setItem("userId",id);   本地存储  两种方式都可以
    $('#right').load('/back/company/contactEdit.html');//页面跳转
}
//删除
function del(id) {
    $.ajax({
        url: '/back/contact/delete',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            if (data.result === 1) {
                $('#right').load('/back/company/contactManage.html');
            } else {
                alert("删除失败");
            }
        }

    })
}